<template>
  <div class="header_box">
    <el-dropdown trigger="click"
                 @command="handleCommand">
      <span class="el-dropdown-link">
        {{username}}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="logout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'Header',

  data () {
    return {
      username: ''
    };
  },

  mounted () {
    if (this.username.length == 0) {
      let res = JSON.parse(window.sessionStorage.getItem('myAppAdmin'))
      this.username = res.username
    }
  },

  methods: {
    handleCommand (command) {
      if (command == "logout") {
        window.sessionStorage.removeItem('myAppAdmin');
        this.$router.push('/login')
      }
    }
  },
};
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.header_box {
  text-align: right;
}
</style>